﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;
using System.Drawing;

[assembly: TagPrefix("CodeWork.WebControls", "ucc")]
namespace CodeWork.WebControls
{
    [SupportsEventValidation, ValidationProperty("Text")]
    [ToolboxData("<{0}:TextBox runat=server></{0}:TextBox>")]
    public class EmailTextBox : TextBox
    {
        private string _defaultColor;
        public string DefaultColor
        {
            get { return this._defaultColor; }
            set { this._defaultColor = value; }
        }

        private string _defaultText;
        public string DefaultText
        {
            get { return this._defaultText; }
            set { this._defaultText = value; }
        }

        private string _actualTextColor;
        public string ActualTextColor
        {
            get { return this._actualTextColor; }
            set { this._actualTextColor = value; }
        }

        private bool _isPostBack;
        public bool IsPostBack
        {
            get { return this._isPostBack; }
            set { this._isPostBack = value; }
        }

        protected override void OnLoad(EventArgs e)
        {
            this.Attributes.Add("onclick","javascript:clearText(this,'"+ DefaultText +"','"+ DefaultColor +"')");
            this.Attributes.Add("onkeyup", "javascript:clearText(this,'" + DefaultText + "','" + DefaultColor + "')");
            this.Attributes.Add("onblur", "javascript:resetText(this,'" + DefaultText + "','" + ActualTextColor + "')");

            if (!IsPostBack)
            {
                Color initialColor = ColorTranslator.FromHtml(DefaultColor);
                this.ForeColor = initialColor;
            }
            else
            {
                Color initialColor = ColorTranslator.FromHtml(DefaultColor);
                Color trueColor = ColorTranslator.FromHtml(ActualTextColor);

                if (this.Text == DefaultText)
                    this.ForeColor = initialColor;
                else
                    this.ForeColor = trueColor;
            }
            base.OnLoad(e);
        }
    }
}
